<template>
	<u-tabbar v-model="current" :list="list" :before-switch="beforeSwitch" :_autoFun="autoFun" :mid-button="true" :mid-button-size="60" ></u-tabbar>
</template>

<script>
	export default {
		name: "tabbar",
		props: {
			_current:{
				type: Number,
				default:0
			},
			getCartNum:{
				type: Number,
				default:0
			}
		},
		data() {
			return {
				list: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
						isDot: false,
						customIcon: false,
						url:'/pages/shop/index/index'
					},
					{
						iconPath: "bag",
						selectedIconPath: "bag-fill",
						text: '商品',
						customIcon: false,
						url:'/pages/shop/goods/index'
					},
					{
						iconPath: "shopping-cart",
						selectedIconPath: "shopping-cart-fill",
						text: '购物车',
						count: 0,
						midButton: true,
						customIcon: false,
						url:'/pages/shop/flow/cart'
					},
					{
						iconPath: "share",
						selectedIconPath: "share-fill",
						text: '分享',
						isDot: false,
						customIcon: false,
						url:'/pages/member/center/myCode'
					},
					{
						iconPath: "account",
						selectedIconPath: "account-fill",
						text: '我的',
						isDot: false,
						customIcon: false,
						url:'/pages/member/center/index'
					},
				],
				current:this._current
			}
		},
		computed:{
			autoFun(){
				if (this.getCartNum == 1){
					this.loadCartNum();
				}
			}
		},
		methods: {
			beforeSwitch(index){
				this.app.goPage(this.list[index].url);
				return false;
			},
			//加载购物车中商品数
			async loadCartNum() {
				this.$u.post('shop/api.flow/getCartInfo').then(res => {
					let cartNum = res.data.num;
					this.$set(this.list[2], 'count', cartNum);
				})
			},
		}
	}
</script>
<style>
</style>
